//
//  ForgotPswViewController.m
//  WangLottery
//
//  Created by 黄修勇 on 12-5-19.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "ForgotPswViewController.h"
#import "RegexKitLite.h"
#import "ChangePswByPhoneNumViewController.h"
#import "WWRequestAPI+WWAccountAPI.h"

@interface ForgotPswViewController ()

@end

@implementation ForgotPswViewController


@synthesize forgotPswTableView=_forgotPswTableView;
@synthesize phoneTxtFiled=_phoneTxtFiled;

-(void)dealloc{

    [_forgotPswTableView release];
    [_phoneTxtFiled release];
    [super dealloc];
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        [self.view setBackgroundColor:[UIColor colorWithRed:0.9 green:0.9 blue:0.96 alpha:1]];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationController.title = @"密码找回";
    self.title=@"密码找回";
    
    // Do any additional setup after loading the view from its nib.
}

-(IBAction)submit:(id)sender{

    [_phoneTxtFiled resignFirstResponder];
    long flag = [[WWRequestAPI currentRequestAPI] forgotPswByTel:_phoneTxtFiled.text target:self];
    if(flag == -1)
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"网络连接失败" message:@"请检查您的网络连接是否正常，并稍后再试" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
}

-(void)showChangeNewsPasswodView{

    ChangePswByPhoneNumViewController *change=[[ChangePswByPhoneNumViewController alloc]initWithNibName:@"ChangePswByPhoneNumViewController" bundle:nil];
    [self.navigationController pushViewController:change animated:YES];
    [change release];
}
- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(void)viewWillDisappear:(BOOL)animated{

    [super viewWillDisappear:animated];
    [_phoneTxtFiled resignFirstResponder];
}
#pragma mark -

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *cellString=@"look for psw";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellString];
    if (!cell) {
        cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellString] autorelease];
        cell.backgroundColor=[UIColor colorWithRed:1.0f green:1.0f blue:1.0f alpha:0.4f];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        cell.textLabel.text=@"手机号:";
        cell.textLabel.backgroundColor=[UIColor clearColor];
        
        UITextField *textFiled=[[UITextField alloc]initWithFrame:CGRectMake(75.0f, 45.0f/2-31.0f/2+4.0f, cell.contentView.frame.size.width-75.0f-20.0f, 31.0f)];
        textFiled.font=[UIFont boldSystemFontOfSize:18.0f];
        textFiled.textColor=[UIColor blackColor];
        textFiled.placeholder=@"输入注册手机号";
        textFiled.clearButtonMode=UITextFieldViewModeWhileEditing;
        textFiled.keyboardType=UIKeyboardTypeNumberPad;
        textFiled.autoresizingMask=UIViewAutoresizingFlexibleWidth;
        [cell.contentView addSubview:textFiled];
        self.phoneTxtFiled=textFiled;
        [textFiled release];
    }
    return cell;
}

#pragma mark -

-(void)requesResult:(NSDictionary *)dic{
    
    NSLog(@"dic %@",dic);
    if([[dic objectForKey:@"result"] isEqualToString:@"0"])
        [self showChangeNewsPasswodView];
    else
        NSLog(@"error:%@",[dic objectForKey:@"result"]);
}
//1!+2!+3!+4!+5!
int sum = 0;

@end
